class Person {
  public name: string; // 定义实例的属性类型， 省略了public等修饰符

  constructor(str: string) {
    this.name = str;
  }

  public getName(): string {
    return this.name;
  }

  public setName(str: string): void {
    this.name = str;
  }
}

const ppl = new Person("John");

class Student extends Person {
  constructor(name: string) {
    super(name);
  }
}

const xm = new Student("Joe");

/*
 * public 类里(this.XXX) 子类(this.XXX) 外部(ppl.XXX) 都可以访问
 * protected 类里 子类
 * private 类里
 * 属性的默认修饰符是public
 */

xm.name;

interface ICard {
  suit: string;
  point: number;
}
interface IDeck {
  suits: string[];
  cards: number[];

  getCards(): () => ICard;
}
// this
const deck: IDeck = {
  suits: ["a", "b", "c", "d"],
  cards: new Array(52),
  getCards() {
    return () => {
      const point = Math.floor(Math.random() * 52);
      // 注意这里的this
      return { suit: this.suits[Math.floor(point / 13)], point: point % 13 };
    };
  }
};

const getCard = deck.getCards();
console.log(getCard());
